library(tidyverse)
library(readxl)
path = "files/Excel Challenge 7th July.xlsx"
input = read_xlsx(path, range = "B3:B20", col_types = "date")
test = read_xlsx(path, range = "D3:D8")
result = input %>%
filter((is.na(lag(SALES)) | is.na(lead(SALES))) & (!row_number() %in% c(1, n())))
identical(result$SALES, test$`Before & After Dates`)
#> [1] TRUECrispo - Excel Challenge 27 2024
excel-challenges
weekly-exercises
Easy Sunday Excel Challenge

Challenge Description
Easy Sunday Excel Challenge
⭐ SALES Before & After Dates NEW ORDER Easy Sunday Excel Challenge ⭐Get the dates BEFORE and AFTER a NEW ORDER marks for Legacy solutions or PowerQuery Solution
Solutions
Logic:
- Applies the workbook rule directly and shapes the expected output
Strengths:
- The R solution stays compact and mirrors the workbook logic closely.
Areas for Improvement:
- The code assumes the workbook layout and named ranges remain stable.
Gem:
- The best part of the solution is choosing a tidy intermediate shape before producing the final answer.
import pandas as pd
import numpy as np
path = "files/Excel Challenge 7th July.xlsx"
input = pd.read_excel(path, usecols="B", skiprows = 2, nrows = 17)
test = pd.read_excel(path, usecols="D", skiprows = 2, nrows = 5)
result = np.where((input["SALES"].shift() == "NEW ORDER") | (input["SALES"].shift(-1) == "NEW ORDER"), 1, 0)
result = input[result == 1].reset_index(drop=True)
result["SALES"] = result["SALES"].astype("datetime64[ns]")
print(result["SALES"].equals(test["Before & After Dates"])) # TrueLogic:
- Reads the workbook range needed for the challenge
Strengths:
- The Python version keeps the same rule in a direct pandas-oriented workflow.
Areas for Improvement:
- As with the R version, any workbook layout change would require small adjustments.
Gem:
- The implementation stays close to the stated challenge instead of adding unnecessary complexity.
Difficulty Level
This task is easy to moderate:
- The business rule is readable, but the workbook still needs a few careful transformation steps.